<template>
<el-card class="box-card">
    <h1>登陆</h1>
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
 <el-form-item label="姓名" prop="name">
    <el-input v-model.number="ruleForm.name"></el-input>
  </el-form-item>
  <el-form-item label="密码" prop="pwd">
    <el-input type="password" v-model="ruleForm.pwd" autocomplete="off"></el-input>
  </el-form-item>
  
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
</el-form>
</el-card>
</template>

<script>

import{login} from '../service'
export default {
    data() {
   
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        } else {
          if (this.ruleForm.checkPass !== '') {
            this.$refs.ruleForm.validateField('checkPass');
          }
          callback();
        }
      };
      return {
        ruleForm: {
          pwd: '',
          name: ''
        },
        rules: {
          pwd: [
            { validator: validatePass, trigger: 'blur' }
          ],
          
          
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate(async(valid)=> {
          if (valid) {
            console.log(this.ruleForm);
           let response= await login(this.ruleForm);
           if(response.status==1){
             alert('登陆成功!');
             this.$router.push("/manager");
           }else{
             alert("登陆失败");
           }
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style>
.box-card{
    margin: auto;
    width: 600px;
}
</style>